# -*- coding: utf-8 -*-

'''

@author: wyndem
@Emil:   wyndem.wen@timevary.com
@FileName: chapter_4.py
@Time: 2018/6/23 10:48
@Description: 快速排序

'''
import math
import demo

'快速排序'
def quicksort(array):
    if len(array)<2:
        return array
    else:
        index=math.ceil((len(array) - 1) / 2)
        piovt=array[index]
        #选出大于piovt的值
        greater=[i for i in array if i > piovt]
        #选出小于piovt的值
        less=[i for i in array if i < piovt]
        #选出等于piovt的值
        center=[array[i] for  i in range(0,len(array)) if array[i]==piovt and i!=index]
        return  quicksort(less) + [piovt]+ center +quicksort(greater)



if __name__ == '__main__':
    ar=quicksort([5, 3, 3, 2, 12, 3, 6])
    print(ar)
    print(demo.binay_search(ar,5))

